<?php

class spListBox extends spSelect
{
	private $item_count = 1;		// note: the list box looks strange if there is only one item in it, that is why we start at item_count=1

	public function __construct( $data=null )
	{
		parent::__construct( $data );
	}
	
	public function addItemText( $text )
	{
		$this->addChild(
			new spOption(array(
				"content" => $text
			))
		);
		
		$this->item_count++;
	}
	
	public function addItemsTextArray( $ar )
	{
		foreach ( $ar as $a )
		{
			$this->addItemText( $a );
		}
	}	
	
	/*
		$ar = array(
			array(
				"content" => "yourcontent",
				"value" => "yourvalue"
			),
			array(
				"content" => "yourcontent",
				"value" => "yourvalue"
			)
		)
	*/
	
	public function addItem( $item )
	{
		$class 		= isset( $item["class"] ) 	? $item["class"] 	: "";
		$content 	= isset( $item["content"] ) ? $item["content"] 	: "";
		$value	 	= isset( $item["value"] ) 	? $item["value"] 	: "";
	
		$this->addChild(new spOption(array(
			"class" 	=> $class,
			"content" 	=> $content,
			"value" 	=> $value
		)));
		
		$this->item_count++;
	}
	
	public function addItems( $ar )
	{
		foreach ( $ar as $a )
		{
			$this->addItem( $a );
		}
	}
	
	public function render( $indent=0 )
	{
		parent::addAttr( "size", $this->item_count );
	
		parent::render( $indent );
	}
}

?>